<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html>
<head>
    <meta charset="UTF-8">
    <title>客房管理</title>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/hotel.css"/>
    <!--<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>-->
    <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
</head>
<body class="roomstatus-body">
<input type="hidden" id="RuserName" th:value="${session.UserName}"/>
<input type="hidden" id="UserStatusid" th:value="${session.UserStatusid}"/>
<input type="hidden" id="UserType" th:value="${session.UserType}"/>
<script type="text/javascript">
    var uname = $('#RuserName').val();
    if(uname == ''){
        window.location.href = "toLogin.do";
    }
    var ustatusid = $('#UserStatusid').val();
    if(ustatusid == 1){
        window.location.href = "toDecode.do";
    }
    var UserType = $('#UserType').val();
    if(UserType === '经理'){
        window.location.href = "toStatement.do";
    }
</script>
<div class="roomstatus-button">
    <div class="roomstatus-button-detail">
        <form action="" method="post">
            <div class="roomstatus-button-text">
                <ul>
                    <li>房间状态:</li>
                    <li>房间类型:</li>
                </ul>
            </div>
            <div class="roomstatus-button-input">
                <ul>
                    <li>
                        <select id="roomstate" name="roomState">
                            <option value="已入住">已入住</option>
                            <option value="已预订">已预订</option>
                        </select>
                    </li>
                    <li>
                        <select id="roomtype" name="roomType">
                            <option value="单人间">单人间</option>
                            <option value="标准间">标准间</option>
                            <option value="双人间">双人间</option>
                            <option value="豪华套房">豪华套房</option>
                            <option value="总统套房">总统套房</option>
                        </select>
                    </li>
                </ul>
            </div>
            <button type="button" id="selectbtn">查询</button>
        </form>
    </div>
    <div class="roomstatus-button-two">
        <ul>
            <li><a href="javascript:;" onclick="emptyroom()">所有空房</a></li>
        </ul>
    </div>
</div>
<div class="roomstatus-detail">
    <table>
        <thead>
            <tr>
                <td width="80px">房间号</td>
                <td width="120px">房间类型</td>
                <td width="60px">住客</td>
                <td width="120px">房间状态</td>
                <td width="120px">预订时间</td>
                <td width="120px">到期时间</td>
                <td width="120px">入住时间</td>
                <td width="120px">退房时间</td>
            </tr>
        </thead>
        <tbody id="roomstatusTbody">

        </tbody>
    </table>
    <div class="roomstatus-center">
        <ul class="pagination" id="page">

        </ul>
        共<span id="totalPage"></span>页
    </div>
</div>
</body>
<script type="text/javascript">
    findByPage1(1);
    function findByPage1(page){
        $('#roomstatusTbody').empty();
        var currentPage = page;
        $.post(
            "roomstatusList.do",
            {'currentPage': currentPage,'rstate':rstate,'rtype':rtype},
            function (data){
                if (data.status == 0){
                    var pageBean = data.result;
                    var totalPage = pageBean.totalPage;
                    var RoomstatusList = pageBean.lists;
                    var no = pageBean.pageSize * (currentPage - 1);
                    for (var i = 0;i<RoomstatusList.length;i++){
                        $('#roomstatusTbody').append('<tr>' +
                            '<td width="60px">'+RoomstatusList[i].roomId+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomType+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomName+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomState+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomReserve+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomExpire+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomIn+'</td>'+
                            '<td width="200px">'+RoomstatusList[i].roomOut+'</td>'+
                            '</tr>');
                    }
                    $('#page').empty();
                    var begin = 1;
                    var end = 1;
                    if (totalPage <= 5) {
                        begin = 1;
                        end = totalPage;
                    } else {
                        begin = currentPage - 2;
                        end = currentPage + 2;
                        if (begin <= 1) {
                            begin = 1;
                            end = 5;
                        }
                        if (end >= totalPage) {
                            begin = totalPage - 4;
                            end = totalPage;
                        }
                    }
                    //添加上一页的按钮
                    $('#page').append('<li id="left" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage1(' + (currentPage - 1) + ')" >&laquo;</span></li>');
                    //添加中间的页数
                    for (var i = begin; i <= end; i++) {
                        $('#page').append('<li class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><a onclick="findByPage1(' + i + ')">' + i + '</a></li>');
                    }
                    //添加下一页的按钮
                    $('#page').append('<li id="right" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage1(' + (currentPage + 1) + ')" >&raquo;</span></li>');
                    if (currentPage == 1) {
                        //添加禁用样式
                        $('#left').addClass('disabled');
                        //清除点击事件
                        $('#left>span').removeAttr('onclick');
                    }
                    if (currentPage == totalPage) {
                        //添加禁用样式
                        $('#right').addClass('disabled');
                        //清除点击事件
                        $('#right>span').removeAttr('onclick');
                    }
                    //添加当前页的激活样式
                    $('#page>li').eq(currentPage - begin + 1).addClass('selectPage');
                    //显示总页数
                    $('#totalPage').html(totalPage);
                }else{
                    layer.msg(data.message);
                }
            }
        );
    }
    var rstate;
    var rtype;
    $('#selectbtn').click(function (){
        rstate = $('#roomstate').val();
        rtype = $('#roomtype').val();
        $('#roomstate').change(function (){
            rstate = $('#roomstate').val();
        })
        $('#roomtype').change(function (){
            rtype = $('#roomtype').val();
        })
        findByPage1(1);
    })
    function findByPage(page){
        $('#roomstatusTbody').empty();
        var currentPage = page;
        $.post(
            "roomstatusList.do",
            {'currentPage': currentPage,'eroom': eroom},
            function (data){
                if (data.status == 0){
                    var pageBean = data.result;
                    var totalPage = pageBean.totalPage;
                    var RoomstatusList = pageBean.lists;
                    var no = pageBean.pageSize * (currentPage - 1);
                    for (var i = 0;i<RoomstatusList.length;i++){
                        $('#roomstatusTbody').append('<tr>' +
                            '<td width="60px">'+RoomstatusList[i].hotelId+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].hotelType+'</td>'+
                            '<td width="100px"></td>'+
                            '<td width="100px">'+RoomstatusList[i].hotelState+'</td>'+
                            '<td width="100px"></td>'+
                            '<td width="100px"></td>'+
                            '<td width="100px"></td>'+
                            '<td width="200px"></td>'+
                            '</tr>');
                    }
                    $('#page').empty();
                    var begin = 1;
                    var end = 1;
                    if (totalPage <= 5) {
                        begin = 1;
                        end = totalPage;
                    } else {
                        begin = currentPage - 2;
                        end = currentPage + 2;
                        if (begin <= 1) {
                            begin = 1;
                            end = 5;
                        }
                        if (end >= totalPage) {
                            begin = totalPage - 4;
                            end = totalPage;
                        }
                    }
                    //添加上一页的按钮
                    $('#page').append('<li id="left" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage(' + (currentPage - 1) + ')" >&laquo;</span></li>');
                    //添加中间的页数
                    for (var i = begin; i <= end; i++) {
                        $('#page').append('<li class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><a onclick="findByPage(' + i + ')">' + i + '</a></li>');
                    }
                    //添加下一页的按钮
                    $('#page').append('<li id="right" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage(' + (currentPage + 1) + ')" >&raquo;</span></li>');
                    if (currentPage == 1) {
                        //添加禁用样式
                        $('#left').addClass('disabled');
                        //清除点击事件
                        $('#left>span').removeAttr('onclick');
                    }
                    if (currentPage == totalPage) {
                        //添加禁用样式
                        $('#right').addClass('disabled');
                        //清除点击事件
                        $('#right>span').removeAttr('onclick');
                    }
                    //添加当前页的激活样式
                    $('#page>li').eq(currentPage - begin + 1).addClass('selectPage');
                    //显示总页数
                    $('#totalPage').html(totalPage);
                }else{
                    layer.msg(data.message);
                }
            }
        );
    }
    var eroom;
    function emptyroom() {
        eroom = '空';
        findByPage(1);
    }
</script>
</html>
